package com.hzx.controller;

import com.hzx.pojo.Sort;
import com.hzx.service.KindService;
import com.hzx.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class OrderPageController {

    @Autowired
    private OrderService orderService ;

    @Autowired
    private KindService kindService ;

    @GetMapping({"/order-page.html","/order-page"})
    public String orderPage(Model model){
        System.out.println("hahahhaha");
        List orderList = orderService.getAllOrder();
        Map kindMapper = getKindMapper();
        model.addAttribute("orders",orderList) ;
        model.addAttribute("kindmapper",kindMapper) ;
        return "order-page" ;
    }

    private Map getKindMapper() {
        Map map = new HashMap<Integer,String>() ;
        List list = kindService.getAllKind() ;
        for (Object o : list) {
            Sort sort =(Sort) o ;
            map.put(sort.getId(),sort.getKind()) ;
        }
        return map ;
    }

    @GetMapping("/single-post.html")
    public String tosinglepost(){
        return "single-post";
    }

    //获取求购信息集
    public String getOrder(){
        return "null" ;
    }

    //通过种类筛选获取求购列表
    public String getOderByKind(){
        return "" ;
    }

    //通过时间发布筛选获取列表
    public String getOrderByTime(){
        return "" ;
    }
}
